/**
 * Copyright (c) Software Institutde of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.core;

import org.eclipse.emf.ecore.EClass;
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.xml.XMLUtility;

/**
 * @author zl
 *
 */
public class MetaEnumLiteral extends MetaNamedElement {
	protected static final int VALUE_DEFAULT = 0;
	protected int value = VALUE_DEFAULT;
	
	@MethodProperty(
			id = "ENUMLITERAL_GET_VALUE",
			catalog = "Model",
			name = CorePackage.ENUMLITERAL_VALUE,
			setter = "setValue"
			)
	public int getValue() {
		return value;
	}

	public void setValue(int newValue) {
		int oldValue = newValue;
		value = newValue;
		firePropertyChange("value", oldValue, newValue);
	}
	
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root, CorePackage.ENUMLITERAL_VALUE, value);
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		value = XMLUtility.xmlInstance.deSerializeInt(root, CorePackage.ENUMLITERAL_VALUE);
	}
	
	@Override
	protected EClass eStaticClass() {
		return EMetaModelPackage.Literals.EMETA_ENUM_LITERAL;
	}
	
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EMetaModelPackage.EMETA_ENUM_LITERAL__VALUE:
				return new Integer(getValue());
		}
		return super.eGet(featureID, resolve, coreType);
	}
}
